package com.wc.alorithm_luogu.P1424;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/4/19 12:35
 * @description https://www.luogu.com.cn/problem/P1424
 * 小鱼的航程(改进版)
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 周x
        long x = sc.nextLong();
        // 经过 n 天
        long n = sc.nextLong();
        // 一共能划
        long sum = 0;
        // 表示一天能游泳的距离
        long distant = 250;

        Main main = new Main();
//        for (long i = 1; i < 8; i++) {
//            for (long j = 1; j < 100; j++) {
//                System.out.println(i + "\t" + j + "\t" + main.swim(i,j,distant) + "\t" + main.swim2(i,j,distant));
//            }
//        }
//        System.out.println(11*1250 + 250);
        System.out.println(main.swim(x, n, distant));
    }

    public long swim(long x, long n, long distant) {
        // 一共能划
        long sum = 0;
        // 循环7日
        sum += (n / 7 * 5 * distant);
        // 循环日去掉
        n = n % 7;


        // 剩余天数的
        while (n-- > 0) {
            if (x < 6) {
                sum += distant;
            }
            if (x == 7) {
                x = 0;
            }

            x++;
        }

        return sum;
    }

    public long swim2(long begin, long day, long distant) {
        long week = day / 7;
        long extraDay = day % 7;
        long mile = week * 5 * 250;
        for (int i = 0; i < extraDay; i++) {
            if (begin < 6) {
                mile += 250;
            }
            if (begin == 7) {
                begin = 0;
            }


            begin++;
        }
        return mile;
    }
}
